﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace eTech_Physics_Sandbox
{
    class DrawLine
    {
        public static Texture2D SourceTexture = null;

        public static void DrawLineSegment(SpriteBatch spriteBatch, Vector2 point1, Vector2 point2, Color color, int lineWidth)
        {
            float dy = point2.Y - point1.Y;
            float dx = point2.X - point1.X; 

            float angle = (float)Math.Atan2(dy, dx);
            float length = (float)Math.Sqrt((dx * dx) + (dy * dy));

            if(SourceTexture != null)
            {
                spriteBatch.Draw(SourceTexture, point1, null, color, angle, Vector2.Zero, new Vector2(length, lineWidth), SpriteEffects.None, 0f);
            }
            
        }

        public static void DrawPolygon(SpriteBatch spriteBatch, Vector2[] vertex, int count, Color color, int lineWidth)
        {
            if (count > 0)
            {
                for (int i = 0; i < count - 1; i++)
                {
                    DrawLineSegment(spriteBatch, vertex[i], vertex[i + 1], color, lineWidth);
                }
                //DrawLineSegment(spriteBatch, vertex[count - 1], vertex[0], color, lineWidth);
            }
        }
    }
}
